package com.bynk.bynk_demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bynk.bynk_demo.common.result.Result;
import com.bynk.bynk_demo.dao.BookMapper;
import com.bynk.bynk_demo.model.Book;
import com.bynk.bynk_demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/book")
//允许该controller所有跨域请求
@CrossOrigin
public class BookController {
    @Autowired
    private BookService bookService;

    @Autowired
    private BookMapper bookMapper;


    @GetMapping("/init")
    public Result init(){
        return Result.success(bookService.getAllBook());
    }

    @GetMapping("/search")
    public Result search(@RequestBody Map map){
        return Result.success(bookService.getAllBook());
    }
    @PostMapping("/m2")
    public IPage m2(@RequestBody Map<String,Long> map){

        Long currentPage =map.get("current");
        Long size =  map.get("size");
        Page<Book> bookPage = new Page<>(currentPage, size);
        // 0表示页数，2表示每页多少个
        IPage ipage = bookMapper.selectPage(bookPage, null);
        System.out.println(ipage);
        return ipage;
    }
}
